﻿using AopFilters.Models;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AopFilters
{
    /// <summary>
    /// 请求结果返回前必会执行
    /// </summary>
    public class KmAsyncAlwaysRunResultFilter : IAsyncAlwaysRunResultFilter
    {
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            if (context.IfIgnoreFilter(typeof(KmAsyncAlwaysRunResultFilter)))
            {
                await next.Invoke();
                return;
            }
            Console.WriteLine("【AlwaysRunResultFilter】开始...");
            ResultExecutedContext resultExecutedContext = await next.Invoke();
            Console.WriteLine("【AlwaysRunResultFilter】结束...");
        }
    }
}
